package wyp.library.http;

import android.os.AsyncTask;

public abstract class WypHttpTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {

	public interface TaskDelegate {
		public void faild_TaskDelegate(int _taskId, Object _object);

		public void success_TaskDelegate(int _taskId, Object _object);
	}

	public interface TaskOtherDelegate {
		public void onPreExecute_TaskDelegate(int _taskId);

		public void onProgressUpdate_TaskDelegate(int _taskId, Object... values);
	}

	public TaskDelegate delegate;
	public TaskOtherDelegate otherDelegate;
	public int taskId;

	public WypHttpTask(int _task, TaskDelegate _delegate) {
		super();
		taskId = _task;
		delegate = _delegate;
	}

	@Override
	protected void onPreExecute() {
		if (otherDelegate != null) {
			otherDelegate.onPreExecute_TaskDelegate(taskId);
		}
		super.onPreExecute();
	}

	@Override
	protected void onProgressUpdate(Progress... values) {
		if (otherDelegate != null) {
			otherDelegate.onProgressUpdate_TaskDelegate(taskId, values);
		}
		super.onProgressUpdate(values);
	}

	protected enum TaskStateEnum {
		NORMAL_STATE, SUCCESS_STATE, FAILD_STATE;
	}

	protected TaskStateEnum state = TaskStateEnum.NORMAL_STATE;

	protected String getTag() {
		return this.getClass().getSimpleName();
	}

}
